//
//  MainViewController.swift
//  WeiboMini
//
//  Created by gaoliang on 15/11/17.
//  Copyright © 2015年 gaoliang. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 由于 tabbar是只读 不能直接操作, 如果要修改 可以使用 KVC
        let mainTabBar = tababrController()
        setValue(mainTabBar, forKey: "tabBar")
        
        //添加子视图控制器
        addChildViewController()
    }
    private func addChildViewController() {

        addChildViewController(HomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    // 重载
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        // 设置 vc
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        
        // 添加控制器
        addChildViewController(UINavigationController(rootViewController: vc))
    }
  
}
